<template>
  <div>
    <div ref="pathchart" style="height: 800px" />

    <!--跟踪对话框-->
    <el-dialog :title="title" :visible.sync="isPathDialogOpen2" width="500px" append-to-body>
      <el-table v-loading="loading" :data="dataList2" @selection-change="handleSelectionChange">
        <el-table-column label="指标名称" align="center" prop="standardName" />
        <el-table-column label="指标介绍" align="center" prop="introduction" :show-overflow-tooltip="true" />
        <el-table-column label="得分" align="center" prop="accessResult":show-overflow-tooltip="true"></el-table-column>
      </el-table>
    </el-dialog>
  </div>

</template>

<script>
import * as echarts from "echarts";
import {getMenu} from "@/api/system/menu";
import{getResultTrend} from"@/api/evaluate/evaluateResult"
export default {
  name: "path",
  data() {
    return {
      pathchart: null,
      isPathDialogOpen2: false,
      trendData: [],
      xAxisData: [],
      yAxisData: [],
      dataList2:[
        {
          standardName: '指标1',
          introduction:'介绍1',
          accessResult:'92',
        },
        {
          standardName: '指标2',
          introduction:'介绍2',
          accessResult:'92',
        },
        {
          standardName: '指标3',
          introduction:'介绍3',
          accessResult:'92',
        },
        {
          standardName: '指标4',
          introduction:'介绍4',
          accessResult:'92',
        },
        {
          standardName: '指标5',
          introduction:'介绍5',
          accessResult:'92',
        },
      ],
    }
  },
  async mounted(){
    await this.fetchTrendData();
    await this.renderChart();
  },
  methods:{
    async fetchTrendData() {
      try {
        const response = await getResultTrend(this.$store.state.evaluate.standardId); // 假设这是获取数据的方法
        this.trendData = response.data;

        // 处理数据
        this.trendData.forEach(item => {
          this.xAxisData.push(item.evaluateDate);
          this.yAxisData.push(item.outputValue);
        });
      } catch (error) {
        console.error('Error fetching data:', error);
      }
    },
    renderChart(){
      this.pathchart = echarts.init(this.$refs.pathchart);
      this.pathchart.on('click', (row) => {
        // this.$router.push('/index');
        //对话框
        // this.reset();
        // this.getTreeselect();

          // this.form = response.data;
          // this.isPathDialogOpen2 = true;
          // this.title = "";
        this.$router.push('/access/system/score');

      });
      this.pathchart.setOption({
        tooltip: {
          trigger: "item",
        },
        xAxis: {
          type: 'category',
          data:this.xAxisData
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: "总评得分",
            type: "line",
            // center: ["50%", "38%"],
            data: this.yAxisData,
            animationEasing: "cubicInOut",
            animationDuration: 1000,
          }
        ]
      });
      window.addEventListener("resize", () => {
        this.pathchart.resize();
      });
    }
  }
}
</script>

<style scoped>

</style>
